﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Media3D;
using Eniux.Windows.ThreeDEngine.Helper;

namespace Eniux.Windows.ThreeDEngine.Visual3Ds
{
    /// <summary>
    /// 管状体
    /// </summary>
    public class PipeVisual3D : HitMeshElement3D
    {
        #region 注册依赖属性

        #region Diameter

        /// <summary>
        ///Diameter属性
        /// </summary>
        public static readonly DependencyProperty DiameterProperty = DependencyProperty.Register(
            "Diameter", typeof(double), typeof(PipeVisual3D), new UIPropertyMetadata(1.0, GeometryChanged));


        /// <summary>
        /// 获取或设置管的外径
        /// </summary>
        public double Diameter
        {
            get { return (double)GetValue(DiameterProperty); }
            set { SetValue(DiameterProperty, value); }
        }

        #endregion

        #region InnerDiameter

        /// <summary>
        /// InnerDiameter属性
        /// </summary>
        public static readonly DependencyProperty InnerDiameterProperty = DependencyProperty.Register(
            "InnerDiameter", typeof(double), typeof(PipeVisual3D), new UIPropertyMetadata(0.0, GeometryChanged));

        /// <summary>
        /// 获取或设置管的内径
        /// </summary>
        public double InnerDiameter
        {
            get { return (double)GetValue(InnerDiameterProperty); }
            set { SetValue(InnerDiameterProperty, value); }
        } 

        #endregion

        #region Point1

        /// <summary>
        /// Point1属性
        /// </summary>
        public static readonly DependencyProperty Point1Property = DependencyProperty.Register(
            "Point1",
            typeof(Point3D),
            typeof(PipeVisual3D),
            new UIPropertyMetadata(new Point3D(0, 0, 0), GeometryChanged));

        /// <summary>
        /// 获取或设置第一个端点
        /// </summary>
        public Point3D Point1
        {
            get { return (Point3D)GetValue(Point1Property); }
            set { SetValue(Point1Property, value); }
        } 
        #endregion

        #region Point2

        /// <summary>
        /// Point2属性
        /// </summary>
        public static readonly DependencyProperty Point2Property = DependencyProperty.Register(
            "Point2",
            typeof(Point3D),
            typeof(PipeVisual3D),
            new UIPropertyMetadata(new Point3D(0, 0, 10), GeometryChanged));

        /// <summary>
        /// 获取或设置第二个端点
        /// </summary>
        public Point3D Point2
        {
            get { return (Point3D)GetValue(Point2Property); }
            set { SetValue(Point2Property, value); }
        } 

        #endregion

        #region ThetaDiv

        /// <summary>
        /// ThetaDiv属性
        /// </summary>
        public static readonly DependencyProperty ThetaDivProperty = DependencyProperty.Register(
            "ThetaDiv", typeof(int), typeof(PipeVisual3D), new UIPropertyMetadata(36, GeometryChanged));

        /// <summary>
        /// 获取或设置角度
        /// </summary>
        public int ThetaDiv
        {
            get { return (int)GetValue(ThetaDivProperty); }
            set { SetValue(ThetaDivProperty, value); }
        } 
        #endregion

        #endregion

        #region 重写方法

        protected override MeshGeometry3D Tessellate()
        {
            var builder = new MeshBuilder();
            builder.AddPipe(Point1, Point2, InnerDiameter, Diameter, ThetaDiv);
            return builder.ToMesh();
        }

        #endregion
    }
}
